import { Component, OnInit } from '@angular/core';
import { PeopleService} from '../service/people.service';
import {People} from '../people';
import { Routes} from '@angular/router';
import { Router} from '@angular/router';
import {AppRoutingModule} from '../app-routing.module';

@Component({
  selector: 'app-new-reader',
  templateUrl: './new-reader.component.html',
  styleUrls: ['./new-reader.component.css']
})
export class NewReaderComponent implements OnInit {
  [x: string]: any;

  peoples: People[];
  position: number;
  count: number;
  constructor(private peopleService: PeopleService, private router: Router) {}

  onRegister(rname: string,pid: number,password: string,passwordAgain: string): void {
    rname = rname.trim();
    password = password.trim();
    this.position = 1;
    this.count = 0;
    if(!rname){
      console.log("用户名不能为空，请检查后重新输入！");
      alert("用户名不能为空，请检查后重新输入！");
      return;
    }
    if (!pid){
      console.log("学号不能为空，请检查后重新输入！");
      alert("学号不能为空，请检查后重新输入！");
      return;
    }
    if (!password){
      console.log("密码不能为空，请检查后重新输入！");
      alert("密码不能为空，请检查后重新输入！");
      return;
    }
    if (!passwordAgain){
      console.log("确认密码不能为空，请检查后重新输入！");
      alert("认密码不能为空，请检查后重新输入！");
      return;
    }
    if(password !== passwordAgain){
      console.log("确认密码和密码不同，请检查后重新输入！");
      alert("确认密码和密码不同，请检查后重新输入！");
      return;
    }

    this.peopleService.createReaderByAll(rname,pid,password,this.position,this.count);
      //.then(people => {
        //this.peoples.push(people);
      //});
    this.router.navigate(['login']);
  }
  
  ngOnInit() {
  }

}

